package com.demo.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.demo.server.annotation.HandleLog;
import com.demo.server.entity.Device;
import com.demo.server.entity.req.CommonSearchReq;
import com.demo.server.entity.req.DeviceAddReq;
import com.demo.server.entity.req.DeviceSwitchReq;
import com.demo.server.entity.req.IdReq;
import com.demo.server.mapper.DeviceMapper;
import com.demo.server.service.DeviceService;
import com.demo.server.util.Result;
import com.demo.server.util.ResultPage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("device")
@Tag(name="设备接口")
public class DeviceController {

	@Autowired
	DeviceService deviceService;
	
	@Autowired
	DeviceMapper deviceMapper;
	
	@GetMapping("listDevice")
	public String listDevice(){
		return "device/listDevice";
	}
	
	@PostMapping("search")
	@Operation(summary = "查询设备")
	public ResultPage<Device> search(@RequestBody CommonSearchReq req){
		log.info("search>>:{}",req);
		return deviceService.search(req);
	}
	
	
	@HandleLog
	@PostMapping("add")
	@Operation(summary = "添加设备")
	public Result add(@RequestBody DeviceAddReq req){
		log.info("add>>:{}",req);
		return deviceService.add(req);
	}
	
	
	@HandleLog
	@PostMapping("edit")
	@Operation(summary = "修改设备")
	public Result edit(@RequestBody DeviceAddReq req){
		log.info("edit>>:{}",req);
		return deviceService.edit(req);
	}
	
	@HandleLog
	@PostMapping("delete")
	@Operation(summary = "删除设备")
	public Result delete(@RequestBody IdReq req){
		log.info("delete>>:{}",req);
		return deviceService.delete(req.getId());
	}
	
	@HandleLog
	@PostMapping("switchDevice")
	@Operation(summary = "开关设备")
	public Result switchDevice(@RequestBody DeviceSwitchReq req){
		log.info("switchDevice>>:{}",req);
		return deviceService.switchDevice(req);
	}
	
}
